home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / Xerox Workcentre 5335 / Windows Scan / 64-bit_x64 / Russian / cpsimage.cab / data / sys / argTokenClass.elf next >
Text File  |  2009-04-23  |  9KB  |  246 lines

  1. /* $Id: argTokenClass.elf,v 1.7 2009/02/06 15:48:02 campanel Exp $ */
  2. #load "sys/lang.elf";
  3.  
  4. /*****************************************************************************/
  5. /*
  6. ** This class can be used to encode and decode arguements into strings
  7. */
  8. /* @New
  9.    Creates an instance of a ARGTOKEN class for manipulation of string parameters.
  10.    This is a convention that defines an arguement as a string with keyword|type|value.
  11.    Keyword may be any alpha-numeric string. Type is one of: b, d, i, s, or l where l is
  12.    followed by one of the first 4 types. Value is a STRING that will be converted to
  13.    the given data type. In the case of a list the elements are comma separated.
  14.    An example of a list of integers could be "window|li|0,0,100,200". To construct this
  15.    class with the given example use:
  16.   
  17.        ARGTOKEN atk = new (ARGTOKEN, param: "window|li|0,0,100,200");
  18.   
  19.    This CLASS is useful when a script is invoked with a long string of several paramters
  20.    encoded in semicolon separated paramters. See also ARGTOKENPARSE.
  21. */
  22. /* @toString Convert this class to a STRING*/
  23. /* @getKey   Return the keyword of this paramter */
  24. /* @getType  Return the character that indicates the base data type
  25.    (b=BOOLEAN,i=INTEGER,d=DOUBLE,s=STRING,lx=LIST where x is a data type).
  26. */
  27. /* @getValue Return the actual data value as an object. */
  28. /*****************************************************************************/
  29.    
  30. CLASS ARGTOKEN
  31. {
  32.     METHOD New (STRING param) {
  33.         LIST allTokens = param.split( delims: "|" );
  34.         if (allTokens.length() == 3) {
  35.             this.baseString = param;
  36.             this.keyword = allTokens[0];
  37.             this.dataType = allTokens[1];
  38.             if ((this.dataType.length() > 1) &&
  39.                 (this.dataType.index(val:0).strcasecmp(str: "l")) )
  40.             {
  41.                 LIST allList = allTokens[2].split( delims: ",");
  42.                 INTEGER i;
  43.                 OBJECT tmp;
  44.                 for (i=0; i<allList.length(); i++) {
  45.                     /* temporary use of class data field */
  46.                     tmp = this.pushData(t: this.dataType[1], d: allList[i]);
  47.                     this.dL.insert(entry: i, obj: tmp);
  48.                 }
  49.             } else {
  50.                 this.pushData(t: this.dataType, d: allTokens[2]);
  51.             }
  52.         }
  53.     }
  54.  
  55.     METHOD toString ( ) RETURNS ( STRING param) {
  56.         param = this.baseString;
  57.     }
  58.  
  59.     METHOD getKey ( ) RETURNS ( STRING keyword )
  60.     {
  61.         keyword = this.keyword;
  62.     }
  63.  
  64.     METHOD getType ( ) RETURNS ( STRING dtype )
  65.     {
  66.         dtype = this.dataType;
  67.     }
  68.  
  69.  
  70.     METHOD getValue ( ) RETURNS ( OBJECT dvalue )
  71.     {
  72.         if (this.dataType.strcasecmp( str: "b" ))  {
  73.             dvalue = this.dB;
  74.             return;
  75.         }
  76.         if (this.dataType.strcasecmp( str: "i" ))  {
  77.             dvalue = this.dI;
  78.             return;
  79.         }
  80.         if (this.dataType.strcasecmp( str: "d" ))  {
  81.             dvalue = this.dD;
  82.             return;
  83.         }
  84.         if (this.dataType.strcasecmp( str: "s" ))  {
  85.             dvalue = this.dS;
  86.             return;
  87.         }
  88.         if (this.dL)  {
  89.             dvalue = this.dL;
  90.             return;
  91.         }
  92.     }
  93.  
  94.     /*****************************************************************************
  95.     ********************    Any Private Methods?    ******************************
  96.     *****************************************************************************/
  97.     private METHOD pushData( STRING t, STRING d) 
  98.                      RETURNS( OBJECT oby)
  99.     {
  100.         if (t.strcasecmp( str: "b" )) {
  101.             if (d.strcasecmp(str: "false") ||
  102.                 d.strcasecmp(str: "0") )
  103.             {
  104.                 this.dB = FALSE;
  105.             } else {
  106.                 this.dB = TRUE;
  107.             }
  108.             oby = this.dB;
  109.         }
  110.         else if (t.strcasecmp( str: "i" )) {
  111.             this.dI = d;
  112.             oby = this.dI;
  113.         }
  114.         else if (t.strcasecmp( str: "d" )) {
  115.             this.dD = d;
  116.             oby = this.dD;
  117.         }
  118.         else if (t.strcasecmp( str: "s" )) {
  119.             this.dS = d;
  120.             oby = this.dS;
  121.         }
  122.     }
  123.     /*****************************************************************************
  124.     ********************    Internal Data Fields    ******************************
  125.     *****************************************************************************/
  126.  
  127.     STRING baseString;
  128.     STRING keyword;
  129.     STRING dataType;
  130.     BOOLEAN dB;
  131.     INTEGER dI;
  132.     DOUBLE dD;
  133.     STRING dS;
  134.     LIST dL;
  135. }
  136.  
  137.  
  138. /*****************************************************************************/
  139. /*
  140. ** This class can be used to parse a semicolon separated set of parameters into
  141. ** a LIST of ARGTOKENS
  142. */
  143. /* @New
  144.    Creates an instance of a ARGTOKENPARSE class based on a given semicolon separated parmeter
  145.    STRING and holds a LIST of ARGTOKEN objects for script reference. An example construction
  146.    of this class with 3 ARGTOKEN objects:
  147.   
  148.          STRING myargs = "method|s|rotate;iangle|i|90;nomask|b|1";
  149.          ARGTOKENPARSE atkp = new (ARGTOKENPARSE, argList: myargs);
  150.   
  151.    This CLASS is useful when a script requires a complex, variable list of imports
  152.    that are better left "free form".
  153. */
  154. /* @toString Convert this class to a STRING*/
  155. /* @getList  Return the LIST of ARGTOKENs made from the arglist */
  156. /* @invokeListOnObject
  157.   Use object list of ARGTOKENs to invoke a method of the given object obj. Assumes the
  158.   argList used to create this object follows a convention of methods and method
  159.   paramters as:
  160.   
  161.         method|s|methName;paramName|?|values...
  162.   
  163.   Where the keyword method indicates the actual method, the paramName is the actual
  164.   name of the paramter and the actual value is given. Several methods may be invoked.
  165.   For example, given an XIPIMAGE the following will invoke rotate and invert:
  166.   
  167.         method|s|rotate;iangle|i|90;nomask|b|TRUE;method|s|invert
  168.   
  169.   The results of the last method call are returned.
  170. */
  171. /*****************************************************************************/
  172.    
  173. CLASS ARGTOKENPARSE
  174. {
  175.     METHOD New (STRING argList) {
  176.         LIST allTokens = argList.split( delims: ";" );
  177.         if (allTokens.length() > 0) {
  178.             INTEGER i;
  179.             ARGTOKEN curAT;
  180.             for (i=0; i<allTokens.length(); i++) {
  181.                 if (allTokens[i].length() > 0) {
  182.                     curAT = new(ARGTOKEN, param: allTokens[i]);
  183.                     this.ags.insert(entry: i, obj: curAT);
  184.                 }
  185.             }
  186.         }
  187.     }
  188.  
  189.     METHOD getList ( ) RETURNS ( LIST atl )
  190.     {
  191.         atl = this.ags;
  192.     }
  193.  
  194.  
  195.     METHOD invokeListOnObject(OBJECT obj)
  196.                   RETURNS (BOOLEAN executed, LIST result)
  197.     {
  198.         executed = FALSE;
  199.         if ((!obj) || (!this.ags))
  200.             return;
  201.         CLASSREF cr = new(CLASSREF, handle: obj);
  202.         //if (!cr) return;
  203.  
  204.         INTEGER ii;
  205.         INTEGER jj;
  206.         INTEGER pCnt;
  207.         INTEGER tokLen = this.ags.length();
  208.         ARGTOKEN argM;
  209.         STRING methodName;
  210.         LIST paramList;
  211.         for(ii=0; ii<tokLen; ii++) {
  212.             argM = this.ags[ii];
  213.             methodName = argM.getValue();
  214.             /* look ahead to count paramters */
  215.             pCnt = 0;
  216.             for (jj=ii+1; jj<tokLen; jj++) {
  217.                 if (this.ags[jj].getKey().strcasecmp(str:"method")) {
  218.                     jj = tokLen+1;
  219.                 } else {
  220.                     pCnt = pCnt+1;
  221.                 }
  222.             }
  223.             /* Put the paramters onto the call list & advance list pointer - ii*/
  224.             paramList.clear();
  225.             for (jj=1; jj<=pCnt; jj++) {
  226.                 paramList.insert(name: this.ags[jj+ii].getKey(),
  227.                                   obj: this.ags[jj+ii].getValue() );
  228.             }
  229.             ii = ii+pCnt;
  230.             /* Invoke it! */
  231.             
  232.             if ( cr.hasMethod(name: methodName) ) {
  233.                 result = cr.invokeMethod(name: methodName, params: paramList);
  234.                 executed = TRUE;
  235.             }
  236.         }
  237.     }
  238.  
  239.     /*****************************************************************************
  240.     ********************    Internal Data Fields    ******************************
  241.     *****************************************************************************/
  242.  
  243.     STRING baseString;
  244.     LIST ags;
  245. }
  246.